//
//  DBConfigMacro.swift
//  DBCA
//
//  Created by mugua on 2024/6/30.
//

import UIKit

@_exported import SnapKit
@_exported import Kingfisher
@_exported import RxSwift
@_exported import RxCocoa

let DBSessionIDKey = "DBSessionIDKey"
let DBIsIndonesiaKey = "DBIsIndonesiaKey"
let DBLanguageKey = "DBLanguageKey"
let DBLanguageKey_Indonesia = "ADA"
let DBLanguageKey_India = "POP"
let DBPhoneKey = "DBPhoneKey"
let DBLatitude = "DBLatitude"
let DBLongitude = "DBLongitude"

// 会是一个静态的方法，不能这样使用

//let DBSessionID = UserDefaults.standard.value(forKey: DBSessionIDKey)
//let DBCurrentLanguage = UserDefaults.standard.value(forKey: DBLanguageKey)
//let DBPhone = UserDefaults.standard.value(forKey: DBPhoneKey)

//let DBAppVersion = Bundle.main.infoDictionary!["CFBundleShortVersionString"] ?? ""

/// App Language en
//let kAPPLanguage = NSLocale.preferredLanguages[0]


let DBKeyWindow = DBNavigator.keyWindow()
let DBAppDelegate = UIApplication.shared.delegate as! AppDelegate
let DBAppVersion = DBDeviceInfoTool.getAppVersion()
let DBSystemVersion = DBDeviceInfoTool.getSystemVersion()
//let DBIdfa = DBDeviceIDFA.idfaByDevice()
//let DBIdfv = DBDeviceIDFA.getIDFV()

let DBScreenBounds = UIScreen.main.bounds
let DBScreenWidth = UIScreen.main.bounds.width
let DBScreenHeight = UIScreen.main.bounds.height
let Is_iPhone = (UI_USER_INTERFACE_IDIOM() == .phone)
let Is_iPhoneX_inch = Statusbar_Height() > 0 && Is_iPhone
let DBTopSafeHeight = Statusbar_Height()
let DBContentNavBarHeight = 44.0
let DBNavHeight = (DBTopSafeHeight + DBContentNavBarHeight)
let DBTabBarHeight = (49.0 + Bottom_Height())


let DBViewBgColor = DBHexColor("174C29")
let DBViewBgColorSub = DBHexColor("CCFF00")
let DBTextColor = DBHexColor("1A1A1A")
let DBTextColorSub = DBHexColor("B1BEB5")
let DBLineBgColor = DBHexColor("BCBCBC")

func DBHexColor(_ hexString: String) -> UIColor? {
    return UIColor.init(hexString: hexString)
}


func DBFuturaMaxiStd_BookFont(_ size:CGFloat) -> UIFont {
    
    if let font = UIFont(name: "FuturaMaxiStd-Book", size: size) {
        return font
    } else {
        return UIFont.systemFont(ofSize: size)
    }
}

func DBFuturaMaxiStd_LightFont(_ size:CGFloat) -> UIFont {
    
    if let font = UIFont(name: "FuturaMaxiStd-Light", size: size) {
        return font
    } else {
        return UIFont.systemFont(ofSize: size)
    }
}

func DBFuturaMaxiStd_DemiFont(_ size:CGFloat) -> UIFont {
    
    if let font = UIFont(name: "FuturaMaxiStd-Demi", size: size) {
        return font
    } else {
        return UIFont.systemFont(ofSize: size)
    }
}

func DBFuturaMaxiStd_BoldFont(_ size:CGFloat) -> UIFont {
    
    if let font = UIFont(name: "FuturaMaxiStd-Bold", size: size) {
        return font
    } else {
        return UIFont.systemFont(ofSize: size)
    }
}

func DBSemiboldFont(_ size:CGFloat) -> UIFont {
    
    if let font = UIFont(name: "PingFangSC-Semibold", size: size) {
        return font
    } else {
        return UIFont.systemFont(ofSize: size)
    }
}



public func DBLog<T>(_ message: T, file: String = #file, funcName: String = #function, lineNum: Int = #line) {
#if DEBUG
    let fileName = (file as NSString).lastPathComponent
    print("\n********** DBLog-satrt ***********\n\nfileName:\(fileName)\nfuncName:\(funcName)\nlineNum:\(lineNum)\nmessage:\n\n\(message)\n\n********** DBLog-end ***********\n")
#endif
}



func Statusbar_Height() -> CGFloat {
    if #available(iOS 13.0, *) {
        return DBKeyWindow?.windowScene?.statusBarManager?.statusBarFrame.height ?? 0
    } else {
        return UIApplication.shared.statusBarFrame.height
    }
}


func Bottom_Height() -> CGFloat {
    if #available(iOS 11.0, *) {
        return DBKeyWindow?.safeAreaInsets.bottom ?? 0
    } else {
        return 0
    }
}
 
func DBRandomString() -> String {
    let letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
    let lettersCount = letters.count

    let randomBytes = [UInt8](repeating: 0, count: 10).map { _ in
        UInt8.random(in: 0..<UInt8(lettersCount))
    }

    return String(randomBytes.map { letters[letters.index(letters.startIndex, offsetBy: Int($0))] })
}


